package com.kelvin.paopao.widgets.dialog;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RadioGroup;

import com.kelvin.kelvinlib.utils.ToastUtil;
import com.kelvin.paopao.R;
import com.kelvin.paopao.api.RetrofitService;
import com.kelvin.paopao.api.responseBean.CommonListResponse;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by mc on 2017/3/8.
 * 附近的人筛选
 */

public class FilterDialogFragment extends DialogFragment {


    @BindView(R.id.rg)
    RadioGroup rg;
    @BindView(R.id.iv_switch)
    ImageView ivSwitch;

    private boolean isFromFar;
    private String sex;

    @Override
    public void onAttach(Activity activity) {

        super.onAttach(activity);
    }

    public static FilterDialogFragment newInstance() {
        FilterDialogFragment f = new FilterDialogFragment();

        Bundle args = new Bundle();
        f.setArguments(args);

        return f;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {


        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getDialog().getWindow().setWindowAnimations(R.style.animate_dialog);

        View view = inflater.inflate(R.layout.dialog_find_filter, container);
        ButterKnife.bind(this, view);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb1) {

                } else if (checkedId == R.id.rb2) {

                } else {

                }
            }
        });
        return view;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @OnClick({R.id.iv_switch, R.id.tv_cancel, R.id.tv_confirm})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_switch:
                isFromFar = !isFromFar;
                if (isFromFar) {
                    ivSwitch.setImageResource(R.drawable.icon_on_blue);
                } else {
                    ivSwitch.setImageResource(R.drawable.icon_off);
                }
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_confirm:
                if (listener != null) {
                    listener.onComplete(isFromFar, sex);
                }
                dismiss();
                break;
        }
    }

    private OnCompleteListener listener;

    public void setListener(OnCompleteListener listener) {
        this.listener = listener;
    }

    public interface OnCompleteListener {
        void onComplete(boolean isFromFar, String sex);
    }
}
